var Item={
	submit:function(form,jsp,btn){
		var type=$("#"+form).data('type');
		$.post(type+"_"+jsp+".jsp",$(btn).closest("form").serialize(),function(data, textStatus, jqXHR){
			$("#"+form+"Result").html(data);
			setTimeout(function(){
				$("#"+form).modal('hide');//cacher la modal
				$("#"+form+'Body').html("...");
			}, 800);
			rgraph.refreshContent(0);
		}).fail(function() {
			$("#"+form+"Result").html("Une erreur est survenue");
		});
	},
	add:function(btn){
		Item.submit("addModal","add",btn);
	},
	remove:function(btn){
		Item.submit("editModal","delete",btn);
	},
	edit:function(btn){
		Item.submit("editModal","edit",btn);
	},
//import-export
	saveAs:function(obj){
		var text=JSON.stringify(rgraph.toJSON());
		saveAs(new Blob([text],{ "type" : "appliquation/json"}), "mindmap.json");
	},
	open:function(evt){
		var f=evt.target.files[0];
		var reader = new FileReader();
		reader.onload = (function(theFile) {
			return function(e) {
				try{
					var json=JSON.parse(e.target.result);
					rgraph.loadJSON(json);
					rgraph.compute('end');
					rgraph.fx.animate({modes:['polar'],duration:0});
					IHM.showNotification();
				}catch(e){
					alert(e);
				}
			};
		})(f);
		reader.readAsText(f);
	},
}